import 'dart:io';

import 'package:dmz/business/login/contorller/login_main_controller.dart';

import 'package:dmz/routers/routers.dart';
import 'package:dmz/string_res/str_res.dart';
import 'package:dmz/user/user_defurl.dart';
import 'package:dmz/utils/Utils.dart';
import 'package:dmz/utils/injection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import 'string_res/str_res_keys.dart';

Future<void> main() async {
  await initSDK();
  // getAndroidPermission();
  runApp(const MyApp());
}

///初始化SDK
Future<void> initSDK() async {
  WidgetsFlutterBinding.ensureInitialized();
  // EMIBUserManger().initLanguage();
  debugPrint('获取token -- 0000');
  await Injection().init();
  EMIBUserManger().initLanguage();
}

getAndroidPermission() {
  if (Platform.isAndroid) {
    const platform = MethodChannel(Utils.CHANNEL_NAME);
    platform.invokeMethod(Utils.METHOD_REQUEST_PERMISSION, null);
  }
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    debugPrint('获取token -- 11111');
    return ScreenUtilInit(
        designSize: const Size(828, 1792),
        builder: (_, child) => GetMaterialApp(
              title: SR.dmz.tr,
              debugShowCheckedModeBanner: false,
              initialRoute: EMIBUserManger().token.isEmpty
                  ? RouteGet.loginFirst
                  : RouteGet.main,
              getPages: RouteGet.getPages,
              translations: StringRes(),
              locale: EMIBUserManger().locale,
              // locale: const Locale('zh', 'CN'),
              fallbackLocale: const Locale('zh', 'CN'),
              theme: ThemeData(primarySwatch: Colors.blue),
              builder: EasyLoading.init(),
              initialBinding: LoginBinding(),
            ));
  }
}
